package com.awspaas.user.apps.shhtaerospaceindustrial.apartmanage;

import java.util.List;
import java.util.Map;

import com.actionsoft.bpms.commons.database.ColumnMapRowMapper;
import com.actionsoft.bpms.commons.formfile.model.delegate.FormFile;
import com.actionsoft.bpms.server.UserContext;
import com.actionsoft.bpms.server.bind.annotation.Controller;
import com.actionsoft.bpms.server.bind.annotation.Mapping;
import com.actionsoft.bpms.util.DBSql;
import com.actionsoft.sdk.local.SDK;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.awspaas.user.apps.shhtaerospaceindustrial.util.CoreUtil;

@Controller
public class ViolationPictureShowCmd {
	/**
	 * @Desc 根据网格点地址，查询该网格点药品信息
	 * @param uc
	 * @param wgdname  药品地址
	 * @return
	 */
	@Mapping("com.awspaas.user.apps.ViolationPictureShow")
	public static String getViolationPictureShow(UserContext uc) {
		JSONObject result = new JSONObject();
		try {
			String queryUrl =
			    "SELECT BINDID,ID,TARGETMAN,TARGETMANPHONE,VIOLATIONTYPE FROM BO_EU_VIOLATIONREPORT_RECORD order by CREATEDATE desc";
			List<Map<String, Object>> urlList = DBSql.query(queryUrl, new ColumnMapRowMapper(), new Object[]{});
			if(urlList == null || urlList.isEmpty()) {
				result.put("status", "1");
				result.put("message", "未查询到通报图片信息。");
				return result.toString();
			}
			JSONArray tececaiArr = new JSONArray();
			Map<String, Object> urlMap = urlList.get(0);
			String bindid = CoreUtil.objToStr(urlMap.get("BINDID"));
			String boId = CoreUtil.objToStr(urlMap.get("ID"));
			String targetman = CoreUtil.objToStr(urlMap.get("TARGETMAN"));
			String targetmanphone = CoreUtil.objToStr(urlMap.get("TARGETMANPHONE"));
			String violationtype = CoreUtil.objToStr(urlMap.get("VIOLATIONTYPE"));
			List<FormFile> files = SDK.getBOAPI().getFiles(boId, "ANNEX");
			for(FormFile file : files){
				JSONObject tececaitem = new JSONObject();
				tececaitem.put("bindid", bindid);
				tececaitem.put("boId", boId);
				tececaitem.put("targetman", targetman);
				tececaitem.put("targetmanphone", targetmanphone);
				tececaitem.put("violationtype", violationtype);
				String downloadUrl = SDK.getBOAPI().getFileDCContext(file).getDownloadURL();
				tececaitem.put("downloadUrl",downloadUrl);
				tececaiArr.add(tececaitem);
				}
			result.put("status", "0");
			result.put("tececaiArr", tececaiArr);

		} catch (Exception e) {
			e.printStackTrace();
			result.put("status", "1");
			result.put("message", e.getMessage());
		}
		return result.toString();
	}
	
}
